package com.six.util;

import cn.hutool.captcha.LineCaptcha;
import cn.hutool.captcha.ShearCaptcha;
import com.six.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class CaptchaUtil {
    //private static LineCaptcha lineCaptcha= cn.hutool.captcha.CaptchaUtil.createLineCaptcha(200,100);
    public ShearCaptcha captcha=cn.hutool.captcha.CaptchaUtil.createShearCaptcha(400,100,5,4);
    @Autowired
    RedisService redisService;
    public  String[] getImage(){
        captcha.createCode();
        String code=captcha.getCode();
        String key= UUID.randomUUID().toString();
        //将验证码存放起来
        redisService.setex(key,5*60,code);

        String imageBase = captcha.getImageBase64();
        String[] result={key,imageBase};
        return result;

    }

}
